package com.qf.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.pojo.DtsUser;
import com.qf.vo.DayStatis;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author zhaojian
 * @since 2021-05-12
 */
public interface DtsUserMapper extends BaseMapper<DtsUser> {
    /**
     * 统计用户按天的增长量
     * @return
     */
    @Select("SELECT DATE_FORMAT(add_time,\"%Y-%m-%d\") AS dayStr,COUNT(*) AS cnts" +
            " FROM dts_user " +
            " WHERE deleted=0 AND  add_time > DATE_ADD(NOW(),INTERVAL -#{daysAgo} DAY)" +
            " GROUP BY dayStr;")
    public List<DayStatis> statuisIncrUserCnt(@Param("daysAgo") Integer dayAgo);

@Select("   SELECT DATE_FORMAT(add_time,\"%Y-%m-%d\") `day`, " +
        "           COUNT(*) users FROM `dts_user` " +
        "        GROUP BY `day` ")
List<Map> queryUserStat();
}
